<!DOCTYPE html>
<html>

<head lang="en">
    <title>找攻略</title>
    <meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <link rel="stylesheet" href="/js/bootstrap-4.1.1-dist/css/bootstrap.min.css">
    <script src="/js/jquery/jquery.min.js"></script>
    <script src="/js/bootstrap-4.1.1-dist/js/bootstrap.min.js"></script>
    <link rel="stylesheet" href="/css/font/css/font-awesome.min.css"/>
    <link rel="stylesheet" href="/css/reset.css"/>
    <link rel="stylesheet" href="/css/strategy.css"/>
    <script src="/js/plugins/jrender/jrender.min.js"></script>
    <link rel="stylesheet" href="/js/plugins/dialog2/dialog.css"/>
    <script src="/js/plugins/dialog2/dialog.min.js"></script>

    <script>
        $(function () {
            var placeId;
            //查询一篇推荐攻略
            $.get("/travels/commend", {type: 3, pageSize: 1}, function (data) {
                $(".commend").renderValues(data.list[0], {
                    getHref: function (item, value) {
                        var href = $(item).data("href")
                        $(item).prop("href", href + value);
                    }
                })
            });
            //查询所有的推荐游记
            $.get("/strategy", {state: 1, pageSize: 0}, function (data) {
                $(".strategyCommend").renderValues(data,{
                    getHref: function (item, value) {
                        var href = $(item).data("href")
                        $(item).prop("href", href + value);
                    }
                })
            });
            //查询状态为推荐的地区
            $.get("/regions/1", function (data) {
                var region = '';
                var strategy = '';
                $.each(data, function (index, ele) {
                    region += '<li class="nav-item"><a  class="nav-link" data-rid="'+ele.id+'" data-toggle="pill" href="#pills-' + ele.id + '">' + ele.name + '</a></li>'
                    strategy += '<div class="tab-pane fade all" id="pills-' + ele.id + '">' + ele.name + '</div>';
                });
                $("#pills-tab").append(region);
                $("#pills-tabContent").append(strategy);
                //给地区绑定点击事件
                $("#pills-tab [data-rid]").click(function () {
                    currentPage=2;
                    pages=2;
                    placeId=$(this).data("rid");
                    $.get('/regions/'+placeId+'/strategy',function (data) {
                        $("#pills-"+placeId).html(data)
                    },"html")
                })

            });

            var currentPage = 2;
            //总页数
            var pages = 2;
            //是否查询中的标记
            var loading = false;

            function query() {
                //如果正在查询中,就不去查询了
                if(loading){
                    return;
                }
                //设置为正在查询的状态
                loading = true;

                //获取全部攻略数据
                $.get('/regions/'+placeId+'/strategy', {currentPage: currentPage}, function (data) {//pageInfo
                    $.each(data.list,function (index, ele) {
                        //克隆模板
                        var div = $("#template .mb").clone(true);
                        //填充数据
                        $(div).find('img').attr('src',ele.coverUrl);
                        $(div).find('span').html(ele.title);
                        $(div).find('a').attr('href',"../strategyCatalogs.html?id="+ele.id);
                        //append到指定位置
                        $(".classify").append(div);
                    })
                    //当前页加1
                    currentPage++;
                    //总页数
                    pages = data.pages;
                    //设置为没有在查询的状态
                    loading = false;
                },'json')
            }

            //给window绑定滚动事件
            $(window).scroll(function () {
                //判断是否滚动到底部(屏幕高度+html滚动上去隐藏的高度>=html文档的高度)
                if($(window).height()+$(document).scrollTop()+1>=$(document). height()){
                    //如果当前页>总页数就不查询了,如果<=就去查询
                    if(currentPage<=pages&&placeId){
                        query();
                    }else{
                        $(document).dialog({
                            type : 'notice',
                            infoText: '亲,已经到底了!',
                            autoClose: 1500
                        });
                    }
                }
            });

            //搜索跳转页面
            $(".searchBtn").change(function () {
                var keyword = $(this).val();
                window.location.href = "/searchStrategiesResult.html?keyword=" + keyword;
            });
            $(".searchBtn").click(function () {
                if ($(this).val()) {
                    $(this).change();
                }
            });


        })

    </script>
</head>

<body>
<div id="template" style="display: none">
    <div class="col-6 mb">
        <a href="../strategyCatalogs.html?id=">
            <img class="float-left" width="100px">
            <div class="classify-text">
                <span></span>
                <p>0人收藏</p>
            </div>
        </a>
    </div>
</div>


<div class="search-head">
    <div class="row nav-search">
        <div class="col-2">
            <a href="index.html">
                <span><i class="fa fa-chevron-left fa-2x"></i></span>
            </a>
        </div>
        <div class="col-10">
            <div class="input-group-sm search">
                <input class="form-control searchBtn" placeholder="请输入攻略标题">
            </div>
        </div>
    </div>
</div>

<ul class="nav nav-pills nav-justified border border-left-0 border-top-0 border-right-0" id="pills-tab" role="tablist">
    <li class="nav-item">
        <a class="nav-link active show" data-toggle="pill" href="#pills-top">
            <span style="font-weight: bold;">推荐</span>
        </a>
    </li>


</ul>

<div class="tab-content" id="pills-tabContent">
    <div class="tab-pane fade active show" id="pills-top">
        <div class="container commend">
            <a data-href="travelContent.html?id=" render-fun="getHref" render-key="t_id">
                <img render-src="coverUrl">
                <p render-html="title"></p>
            </a>
        </div>
        <hr>
        <div class="container strategyCommend">
            <h6>当季推荐</h6>
            <div class="row hot" render-loop="list" >
                <div class="col-4">
                    <a data-href="strategyCatalogs.html?id=" render-fun="getHref" render-key="list.id">
                        <img render-src="list.coverUrl">
                        <p render-html="list.title"></p>
                    </a>
                </div>
            </div>
        </div>
    </div>

</div>
</body>

</html>